***********************************************************
**** HOW UNCERTAINTY ABOUT WAR OUTCOMES AFFECTS WAR ONSET 
**** BAS AND SCHUB
**** JCR REPLICATION FILE 
***********************************************************


***********************
** CONTENTS OVERVIEW
***********************

* (I) Dyad-year results:
  * Models 2-6 from Table 2
  * Models 8-11 from Table 3
  * Table 4 of Online Appendix
  * Table 6 of Online Appendix
  * Descriptive stats from Table 1 of Online Appendix
  
* (II) System-year results:
  * Model 1 from Table 2
  * Table 3 from Online Appendix
  * Table 5 from Online Appendix
  * Descriptive stats from Table 1 of Online Appendix
  
* (III) Region-year results:
  * Model 7 from Table 3
  * Descriptive stats from Table 1 of Online Appendix
  
* (IV) Dyad-year simulations:
  * Simulations for Figure 2
  * Simulations for Figure 3
  * Simulations referenced in text 
  
* (V) System-year simulations:
  * Simulations referenced in text

* (VI) Region-year simulations:
  * Simulations referenced in text


*************************************************************************
** (I) Reproduce dyad-year model results (main paper and online appendix)
*************************************************************************

* (A) Set working directory and load data
clear
use "DyadYear.dta" 

* (B) Produce Models 2 through 6 from Table 2
logit neworigforce SystemRELa relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_SystemRELa relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_SystemRELa_s1c relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_SystemRELa_d1c relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_SystemRELa con relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)

* (C) Produce Models 8 through 11 from Table 3
logit neworigforce W_Regionalb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_Regionals1cb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_Regionald1cb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3,  cluster(dyad)
logit neworigforce W_Regionalb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3 if year>=1992,  cluster(dyad)

* (D) Produce Table 4 of Online Appendix (joiners and fatalities) 
*create variable for number of states in the conflict
gen join=cwnumst1+cwnumst2

reg cwfatald W_SystemRELa relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3 if neworigforce==1 & cwfatald>=0,  cluster(dyad)
reg join W_SystemRELa relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3 if neworigforce==1,  cluster(dyad)
reg cwfatald W_Regionalb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3 if neworigforce==1 & cwfatald>=0,  cluster(dyad)
reg join W_Regionalb relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3 if neworigforce==1 ,  cluster(dyad)

* (E) Produce Table 6 of Online Appendix (likelihood ratio tests)
logit neworigforce relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3
estimates store m1
logit neworigforce W_SystemRELa relcap contig jdem rival alliance pceyrs pceyrs2 pceyrs3
estimates store m2
lrtest m1 m2

* (F) Produce unreported results with alternative sample criteria (akin to Models 2 through 6 from Table 2) 
*create variable to indicate ongoing conflict and drop these cases from analysis
gen ongoing=0
replace ongoing=1 if neworigforce==0 & cwhostd>3 & cwongo==1

logit neworigforce SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if ongoing==0,  cluster(dyad)
logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if ongoing==0,  cluster(dyad)
logit neworigforce W_SystemRELa_s1c relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if ongoing==0,  cluster(dyad)
logit neworigforce W_SystemRELa_d1c relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if ongoing==0,  cluster(dyad)
logit neworigforce W_SystemRELa con relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if ongoing==0,  cluster(dyad)



* (G) Descriptive stats of upper half from Table 1 of Online Appendix
summ neworigforce SystemRELa W_SystemRELa W_SystemRELa_s1c W_SystemRELa_d1c W_Regionalb W_Regionals1cb W_Regionald1cb relcap contig jdem rival alliance pceyrs 



*************************************************************************
** (II) Reproduce system-year model results (main paper and online appendix)
*************************************************************************

* (A) Set working directory and load data
clear
use "SystemYear.dta"

* (B) Produce Model 1 from Table 2
nbreg neworigforce W_SystemRELa jdem dyads numGPs, robust

* (C) Produce Table 3 from Online Appendix (alternative outcome variables)
nbreg neworigmid W_SystemRELa jdem dyads numGPs, robust
nbreg allforce W_SystemRELa jdem dyads numGPs, robust

* (D) Produce Table 5 from Online Appendix (likelihood ratio test)
nbreg neworigforce W_SystemRELa jdem dyads numGPs
estimates store m1
nbreg neworigforce jdem dyads numGPs
estimates store m2
lrtest m1 m2

* (E) Descriptive stats of middle from Table 1 of Online Appendix
summ neworigforce W_SystemRELa jdem dyads numGPs

*************************************************************************
** (III) Reproduce region-year model results (main paper and online appendix)
*************************************************************************

* (A) Set working directory and load data
clear
use "RegionYear.dta"

* (B) Produce Model 7 from Table 3
nbreg neworigforce reg5_w jdem dyads numGPs, robust

* (C) Descriptive stats of bottom from Table 1 of Online Appendix
summ neworigforce reg5_w jdem dyads numGPs

******************************************
** (IV) Reproduce dyad-year simulation results
******************************************

* (A) Set working directory and load data
clear
use "DyadYear.dta" 

* (B) Produce simulations used for Figure 2
*i) Predicted Probability UK-ARG 1982
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx [60324]
simqi, listx
simqi, prval(1) 

*ii) Predicted Probability UK-US 1868
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx [9466]
simqi, listx
simqi, prval(1) 

*iii) First difference between the two observations
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx [9466]
simqi, listx fd(prval(1)) changex(W_SystemRELa W_SystemRELa[9466] W_SystemRELa[60324] pceyrs pceyrs[9466] pceyrs[60324] pceyrs2 pceyrs2[9466] pceyrs2[60324] pceyrs3  pceyrs3[9466] pceyrs3[60324]) 
*2.61 [1.58,3.90]

* (C) Produce simulations used for Figure 3

*i) All observations using uncertainty score weighted by only capabilities (uses China-Taiwan 1976 dyad) 
*a)Base estimate
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
estsimp logit neworigforce W_Regionalb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx[55103]
setx W_Regionalb p90 
simqi, listx prval(1)

*b)First difference 
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_Regionalb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx[55103]
setx W_Regionalb p90 
simqi, listx fd(prval(1)) changex(W_Regionalb p90 p10)

*ii) All observations using uncertainty score weighted by capabilities and distance (uses Germany-Poland 1933 dyad) 
*a)Base estimate
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
estsimp logit neworigforce W_Regionald1cb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx[29933]
setx W_Regionald1cb p90 
simqi, listx prval(1)

*b)First difference 
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
estsimp logit neworigforce W_Regionald1cb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx[29933]
setx W_Regionald1cb p90 
simqi, listx fd(prval(1)) changex(W_Regionald1cb p90 p10)

*iii) Post-cold war observations using uncertainty score weighted by only capabilities (uses Russia-Latvia 1996 dyad) 
*a)Base estimate
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_Regionalb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if year>1991, robust cluster(dyad)
setx[77568]
setx W_Regionalb p90 
simqi, listx prval(1)

*b) First difference
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_Regionalb relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3 if year>1991, robust cluster(dyad)
setx[77568]
setx W_Regionalb p90 
simqi, listx fd(prval(1)) changex(W_Regionalb p90 p10)

* (D) Produce simulations referenced in text for dyads with rivals
*i) Base estimate with high uncertainty
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx median if rival==1
setx W_SystemRELa p90
simqi, listx prval(1)
*9.74 [8.10,11.52]

*ii) Estimate with low uncertainty
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx median if rival==1
setx W_SystemRELa p10
simqi, listx prval(1)
*15.67 [13.21,18.47]

*iii) First difference
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 
estsimp logit neworigforce W_SystemRELa relcap rival contig jdem alliance pceyrs pceyrs2 pceyrs3, robust cluster(dyad)
setx median if rival==1
setx W_SystemRELa p90
simqi, listx fd(pr) changex(W_SystemRELa p90 p10)
*5.91 [3.52,8.62]


*******************************************************************
** (V) Reproduce system-year simulation results (referenced in text)
*******************************************************************

* (A) Set working directory and load data
clear
use "SystemYear.dta"

* (B) Effect of shifting system year uncertianty from 90th to 10th percentile levels
*i) Base estimate
estsimp nbreg neworigforce W_SystemRELa jdem dyads numGPs, robust
setx median
setx W_SystemRELa p90
simqi, listx ev

*ii) First difference
drop b1 b2 b3 b4 b5 b6
estsimp nbreg neworigforce W_SystemRELa jdem dyads numGPs, robust
setx median
setx W_SystemRELa p90
simqi, listx fd(ev) changex(W_SystemRELa p90 p10)

*******************************************************************
** (VI) Reproduce region-year simulation results (referenced in text)
*******************************************************************

* (A) Set working directory and load data
clear
use "RegionYear.dta"

* (B) Effect of shifting region year uncertianty from 90th to 10th percentile levels
*i) Base estimate
estsimp nbreg neworigforce reg5_w jdem dyads numGPs, robust
setx median
setx reg5_w p90
simqi, listx ev

*ii) First difference
drop b1 b2 b3 b4 b5 b6
estsimp nbreg neworigforce reg5_w jdem dyads numGPs, robust
setx median
setx reg5_w p90
simqi, listx fd(ev) changex(reg5_w p90 p10)






